<?php
/**
 * 用户管理控制器
 * 
 * @author 高强
 */
class Manager_UserController extends Zend_Controller_Action
{
	protected $_output;
	
	public function init()
	{
		Zend_Loader::loadClass('UserModel');
		Zend_Loader::loadClass('RoleModel');
		$this->_output = new Custom_Controller_Plugin_Output();
		$this->view->controller = $this->_request->getControllerName();
	}
	
	public function listAction()
	{
		$action = $this->_request->getParam('a');
		
		switch($action)
		{
			case 'rows':
				$this->_helper->layout->disableLayout();
    			$this->_helper->viewRenderer->setNoRender(true);
    			if($this->_request->isPost())
    			{
    				$post = $this->_request->getPost();
    				$model = new UserModel();
    				$rows = $model->pageRows($post);
    				$this->_output->grid($rows);
    			}
    			
				break;
		}
	}
	
	public function addAction()
	{
		$action = $this->_request->getParam('a');
		
		switch($action)
		{
			case 'submit':
				$this->_helper->layout()->disableLayout();
				$this->_helper->viewRenderer->setNoRender(true);
				
				if($this->_request->isPost())
				{
					$post = $this->_request->getPost();
					$model = new UserModel();
					$rows = $model->add($post);
				}
				break;
				
			case 'combo':
				$this->_helper->layout->disableLayout();
				$this->_helper->viewRenderer->setNoRender(true);
				
				$rolemodel = new RoleModel();
				$rows = $rolemodel->rows();
				
				$this->_output->rows($rows);
				break;
		}
	}
}